/**
 * 获取各平台信息
 * @param {String} name - 厂商+平台名称
 * @param {String} provider - 厂商
 * @param {String} platform - 平台名称
 * @param {String} os - 系统型号
 * @param {Object} device - 设备信息
 */

import wechat from './miniApp'
import app from './app'
import ios from './apple'

const device = uni.getSystemInfoSync()
const os = device.platform

let name = ''
let provider = ''
let platform = ''

// #ifdef APP-PLUS
name = 'App'
platform = 'App'
provider = 'App'
// #endif

// #ifdef MP-WEIXIN
name = 'WeChatMiniProgram'
platform = 'WeChatMiniProgram'
provider = 'wechat'
// #endif

const load = () => {
	// 微信小程序平台检查更新
	if (provider === 'wechat') {
		wechat.checkUpdate()
	} else if (provider === 'App') {
		// APP平台检查更新
		app.checkUpdate()
	}
}

// 根据平台做API操作转发
const useProvider = (_provider = '') => {
	if (_provider === 'wechat') return wechat
	if (_provider === 'app') return app
	if (_provider === 'apple') return ios
}

// 获取各端异形屏信息
const getCapsule = () => {
	// #ifdef MP
	// 小程序端胶囊信息及底部安全区域高度
	return wechat.getCapsule()
	// #endif

	// #ifdef APP-PLUS
	// App端安全区域值
	// top: device.statusBarHeight,
	// bottom: device.safeAreaInsets.bottom,

	// eslint-disable-next-line no-unreachable
	return device.safeArea
	// #endif
}

const capsule = getCapsule()

// 标题栏高度
const getNavBar = () => {
	return device.statusBarHeight + 44
}
const navbar = getNavBar()

const _platform = {
	name,
	device,
	os,
	provider,
	platform,
	capsule,
	navbar,
	load,
	useProvider
}

export default _platform
